package loader

import (
	"os"
	"kumachan/standalone/util/richtext"
	"kumachan/interpreter/lang/common/source"
)


type Context struct {
	ImportPoint  source.Location  // nullable
	LocalAlias   string
	BreadCrumbs  [] Ancestor
}

type Ancestor struct {
	ModuleName  string
	FileInfo    os.FileInfo
	FilePath    string
}

func MakeEntryContext() Context {
	return Context {
		ImportPoint: source.Location {},
		BreadCrumbs: make([] Ancestor, 0),
	}
}

func (ctx Context) WrapErrorDesc(desc richtext.Block) richtext.Block {
	var b richtext.Block
	if ctx.ImportPoint != (source.Location {}) {
		b.WriteSpan("Unable to import module", richtext.TAG_ERR_NORMAL)
		b.WriteLine(ctx.LocalAlias, richtext.TAG_ERR_INLINE)
	} else {
		b.WriteLine(
			"*** Unable to load given source file",
			richtext.TAG_ERR_NORMAL,
		)
	}
	b.Append(desc)
	return b
}


